home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TestDriverMain.c
-
- Contains: Implementation of a very stupid device driver.
-
- Written by: Quinn "The Eskimo!"
-
- Copyright: © 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
- */
-
- #include <Types.h>
- #include <Devices.h>
-
- static pascal OSErr DRVROpen(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
- {
- #pragma unused (paramBlock)
- #pragma unused (devCtlEnt)
- return (noErr);
- }
-
- static pascal OSErr DRVRPrime(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
- {
- #pragma unused (paramBlock)
- #pragma unused (devCtlEnt)
- return (-1);
- }
-
- static pascal OSErr DRVRControl(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
- {
- #pragma unused (paramBlock)
- #pragma unused (devCtlEnt)
- return (controlErr);
- }
-
- static pascal OSErr DRVRStatus(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
- {
- #pragma unused (paramBlock)
- #pragma unused (devCtlEnt)
- OSErr err;
- CntrlParamPtr cpb;
-
- cpb = (CntrlParamPtr) paramBlock;
-
- switch ( cpb->csCode ) {
- case 666:
- cpb->csParam[0] = cpb->ioCRefNum;
- err = noErr;
- break;
- default:
- err = statusErr;
- }
-
- return (err);
- }
-
- static pascal OSErr DRVRClose(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
- {
- #pragma unused (paramBlock)
- #pragma unused (devCtlEnt)
- return (noErr);
- }
-
- OSErr main(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt, short dispatch)
- {
- //
- // Here A4 is already setup to point to our data segment. There is no need
- // to call long oldA4=SetCurrentA4();/SetA4(oldA4); as in code resources.
- //
- // However you have to still have to use "#include <SetupA4.h>;RememberA4();..."
- // when using callback functions.
- //
- // If your routine returns 1 (asynch request can't be completed right away)
- // the Metrowerks startup code will correctly jump to jIODone. You don't need
- // to worry about this issue in this driver.
- //
- OSErr err = noErr;
-
- switch(dispatch)
- {
- case 0: // Open
- err = DRVROpen(paramBlock, devCtlEnt);
- break;
- case 1: // Prime return 1 if async request cannot be completed right away
- err = DRVRPrime(paramBlock, devCtlEnt);
- break;
- case 2: // Control return 1 if async request cannot be completed right away
- err = DRVRControl(paramBlock, devCtlEnt);
- break;
- case 3: // Status return 1 if async request cannot be completed right away
- err = DRVRStatus(paramBlock, devCtlEnt);
- break;
- case 4: // Close
- err = DRVRClose(paramBlock, devCtlEnt);
- break;
- }
- return err;
- }
-